package net.borderwars.util;

import java.util.Enumeration;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.LogManager;
import java.util.logging.Logger;

public class LogInformation {

    public static void getInfo () {
        // Get the Log Manager
        LogManager manager = LogManager.getLogManager ();
        // Get all defined loggers
        Enumeration names = manager.getLoggerNames ();

        System.out.println ("***Begin Logger Information");
        // For each logger: show name, level, handlers etc.
        while (names.hasMoreElements ()) {
            String loggername = (String) names.nextElement ();
            Logger logger = manager.getLogger (loggername);
            System.out.println ("-----------------------");
            System.out.println ("Logger name: >" + logger.getName () + "<");
            System.out.println ("Logger level: " + logger.getLevel ());

            // See if a filter is defined
            if (logger.getFilter () != null)
                System.out.println ("Using a filter");
            else
                System.out.println ("No filter used");

            // For each handler: show formatter, level, etc.
            Handler[] h = logger.getHandlers ();
            if (h.length == 0) System.out.println ("No handlers defined");
            for (int i = 0; i < h.length; i++) {
                if (i == 0) System.out.println ("Handlers:");
                Formatter f = h[i].getFormatter ();
                System.out.println (h[i].getClass ().getName ());
                System.out.println ("  using formatter: " + f.getClass ().getName ());
                System.out.println ("  using level: " + h[i].getLevel ());
                if (h[i].getFilter () != null)
                    System.out.println ("  using a filter");
                else
                    System.out.println ("  no filter");
            }

            // See if a parent exists
            Logger parent = logger.getParent ();
            if (parent != null)
                System.out.println ("Parent: >" + parent.getName () + "<");
            else
                System.out.println ("No parent");
        }
        System.out.println ("*** End Logger Information");
    }

    // Send all message types to the logger
    public static void tryLevels (Logger logger) {
        logger.severe ("severe message");
        logger.warning ("warning message");
        logger.info ("info message");
        logger.config ("config message");
        logger.fine ("fine message");
        logger.finer ("finer message");
        logger.finest ("finest message");
    }
}
